// #ifdef MP-WEIXIN
/* 小程序端 */
export default{
	onLoad() {
		// this.loadAllData('refresh');
	},
	onPullDownRefresh() {
		// this.loadAllData('refresh');
	},
	onReachBottom(){
		// this.loadAllData();
	},
	methods: {
		// 加载热门推荐列表
		// async loadAllData(type='add'){
		// 	let that = this;
		// 	if(type === 'add'){
		// 		if(this.loadingType === 2) return;
		// 		this.page = this.page + 1;
		// 		this.$refs.productList.loadType = 'add';
		// 	}else{
		// 		this.page = 1;
		// 		this.gameList = [];
		// 		if(this.$refs.productList){
		// 			this.$refs.productList.loadType = 'refresh';
		// 		}
		// 	}
		// 	this.loadingType = 1;
		// 	// const res = await this.$request('product', 'getgameList', {
		// 	// 	offset: (this.page - 1) * 10,
		// 	// 	limit: 10,
		// 	// });
		// 	// const res = await util.request(api.IndexUrl).then(function(res) {
		// 	// 		that.log("======"+JSON.stringify(res.data.categories));
		// 	// 		if (res.errno == 0) {
		// 	// 			that.advertList = res.data.advertiseList;
		// 	// 			that.navList = res.data.categories;
		// 	// 		}
		// 	// 	});
		// 	// that.log("===loadData==type="+type);
		// 	// uni.showLoading({
		// 	// 	title: ''
		// 	// })	
		// 	// that.page = that.page + 1;
		// 	const res = await this.$request_mock("GameList", "GameList", {
		// 		pageNo: that.page,
		// 		pageSize: 10
		// 	})
		// 	const curList = res.data.records;
		// 	this.gameList = this.gameList.concat(curList); //追加新数据
		// 	if(type === 'refresh'){
		// 		uni.stopPullDownRefresh();//结束加载状态
		// 	}
		// 	setTimeout(()=>{
		// 		this.loadingType = curList.length < 10 ? 2 : 0;
		// 	}, 300)
		// },
		async loadAllData(type='add'){
			let that = this;
			if(type === 'add'){
				if(this.loadingType === 2) return;
				this.page = this.page + 1;
				this.$refs.rankingList.loadType = 'add';
			}else{
				this.page = 1;
				// this.gameList = [];
				if(this.$refs.rankingList){
					this.$refs.rankingList.loadType = 'refresh';
				}
				await this.loadGameList(type);
			}
			await this.loadRankingList(type);
			// this.loadingType = 1;
			// const res = await this.$request_mock("GameList", "GameList", {
			// 	pageNo: that.page,
			// 	pageSize: 10
			// })
			// const curList = res.data.records;
			// this.gameList = this.gameList.concat(curList); //追加新数据
			// if(type === 'refresh'){
			// 	uni.stopPullDownRefresh();//结束加载状态
			// }
			// setTimeout(()=>{
			// 	this.loadingType = curList.length < 10 ? 2 : 0;
			// }, 300)
		},
		async loadGameList(type){
			// const res = await this.$request_mock("GameList","GameList", {
			// 	pageNo: 1,
			// 	pageSize: 10
			// })
			const res = await this.$request("GameList","GameList", {
				pageNo: 1,
				pageSize: 10,
				status: 1
			})
			// console.log("!!!!!!!!!!!!!!"+JSON.stringify(res));
			const curList = res.result.records;
			// this.gameList = this.gameList.concat(curList); //追加新数据
			this.gameList = curList;
			if(type === 'refresh'){
				uni.stopPullDownRefresh();//结束加载状态
			}
		},
		async loadRankingList(type){
			const res = await this.$request("rankingList","RankingList", {
				pageNo: this.page,
				pageSize: 10
			})
			// console.log("==RankingList=="+JSON.stringify(res))
			const curList = res.result.records;
			if(type === 'refresh'){
				// this.loaded && curList.forEach(item=> {item.loaded = true;})
				this.top3PlayersSource = curList.slice(0, 3)
				// this.top3 = curList.slice(0, 3)
			}
			// console.log("===loadGameList=1=="+JSON.stringify(curList))
			this.rankingList = this.rankingList.concat(curList.slice(3, curList.length)); //追加新数据
			// console.log("===rankingList=="+JSON.stringify(this.rankingList))
			if(type === 'refresh'){
				uni.stopPullDownRefresh();//结束加载状态
			}
		},
	},
}
// #endif

// #ifndef MP-WEIXIN
/* 非小程序端 */
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

export default{
	mixins: [MescrollMixin], 
	data() {
		return {
			upOption:{
				auto: false, // 是否自动加载
				page: {
				 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
				 	size: 10 // 每页数据的数量
				},
				noMoreSize: 1,
			},
		}
	},
	computed: {
		headerHeight(){
			return 750 / uni.upx2px(750) * (this.systemInfo.navigationBarHeight + this.systemInfo.statusBarHeight);
		}
	},
	methods: {
		//加载热门推荐列表
		async loadAllData(e){
			// console.log("===loadData==="+this.$refs.productList)
			let that = this;
			// this.log("===loadData==e="+JSON.stringify(e));
			if(e.num === 1){
				//第一页清空数据重载
				this.page = 1;
				// this.gameList = [];
				if(this.$refs.rankingList){
					this.$refs.rankingList.loadType = 'refresh';
				}
				// await this.loadGameList(e);
			}else{
				this.page = this.page + 1;
				this.$refs.rankingList.loadType = 'add';
			}
			
			// await this.loadRankingList(e);
			// console.log(JSON.parse(JSON.stringify(res.data)));
		},
		async loadGameList(e){
			// console.log("===loadGameList=1==")
			// let that = this;
			// that.gameList = [];
			// that.$refs.gameList.loadType = 'refresh';
			const res = await this.$request("GameList","GameList", {
				pageNo: 1,
				pageSize: 10
			})
			// console.log(JSON.stringify(res));
			const curList = res.result.records;
			this.loaded && curList.forEach(item=> {item.loaded = true;})
			this.gameList = this.gameList.concat(curList); //追加新数据
			// this.mescroll.endSuccess(curList.length); //结束加载状态
		},
		async loadRankingList(e){
			const res = await this.$request("rankingList","RankingList", {
				pageNo: this.page,
				pageSize: 10
			})
			// console.log("==RankingList=="+JSON.stringify(res))
			const curList = res.result.records;
			if(e.num === 1){
				this.loaded && curList.forEach(item=> {item.loaded = true;})
				this.top3PlayersSource = curList.slice(0, 3)
				// this.top3 = curList.slice(0, 3)
			}
			// console.log("===loadGameList=1=="+JSON.stringify(curList))
			this.rankingList = this.rankingList.concat(curList.slice(3, curList.length)); //追加新数据
			// console.log("===rankingList=="+JSON.stringify(this.rankingList))
			this.mescroll.endSuccess(curList.length); //结束加载状态
		},
		mescrollInit(mescroll){
			this.isLoading = true;
			this.mescroll = mescroll;
			this.mescroll.resetUpScroll(false)
		}
	},
}
// #endif
